package Zuoye.zuoye4;

public class Tool {
    public static int dichotomy(double[] arr, double num) {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] == num) {
                System.out.println("找到了：" + num);
                return mid;
            } else if (num > arr[mid]) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        System.out.println("没有找到" + num);
        return -1;
    }

}
